package com.tuling.bootquartz;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

@DisallowConcurrentExecution    // 禁止并发执行同一个Job定义的多个实例
@PersistJobDataAfterExecution   // 持久化JobDetail中的JobDataMap(对Trigger中无效)
public class QuartzJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            Thread.sleep(2000);
            System.out.println(context.getScheduler().getSchedulerInstanceId());
            System.out.println("taskName：" + context.getJobDetail().getKey().getName());
            System.out.println("执行时间：" + new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
